package com.gitee.feizns.explore.data_structure.tree.bs.mid;

/**
 * @author feizns
 * @since 2020/3/9
 */
public class KthSmallest {

    public static void main(String[] args) {

    }

    static int K = 0;

    public static int kthSmallest(TreeNode root, int k) {
        if ( root != null ) {
            int l = kthSmallest(root.left, k);
            if ( l != -1 )
                return l;
            K++;
            if ( k == K )
                return root.val;
            return kthSmallest(root.right, k);
        }
        return -1;
    }

}
